import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-15
 * Time: 8:03
 */
public class Demo2 {
    public static void main(String[] args) {
        Object locker1 =new Object();
        synchronized (locker1){

        }
        ReentrantLock locker=new ReentrantLock(true);
        //参数写true就是创建一个公平锁
        //不写或写false就是创建一个非公平锁
        try{
            locker.lock();//加锁
        }finally {
            locker.unlock();//解锁
            //因为可以会忘记写解锁方法,或者因其他方法返回,没执行了解锁操作,
            //所以经常把解锁操作放到finally中,该方法就一定会被执行
        }



    }
}
